package com.tianyang.yukuaifuzs.business.trade.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.tianyang.yukuaifuzs.R;
import com.tianyang.yukuaifuzs.business.trade.provider.TradeOpenProvider;
import com.tianyang.yukuaifuzs.utils.VerifyUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Description：服务商平台顶部view
 * Created by xyj on 2024/3/25
 */
public class ServicePlatformHeaderView extends LinearLayout {

    @BindView(R.id.todayTradeAmountTv)
    TextView todayTradeAmountTv;
    @BindView(R.id.todayTradeCountTv)
    TextView todayTradeCountTv;
    @BindView(R.id.totalMerchantNumberTv)
    TextView totalMerchantNumberTv;
    @BindView(R.id.todayProfitTv)
    TextView todayProfitTv;
    @BindView(R.id.todayTradeUserTv)
    TextView todayTradeUserTv;
    @BindView(R.id.merchantNumberTv)
    TextView merchantNumberTv;

    public ServicePlatformHeaderView(Context context, AttributeSet attrs) {
        super(context, attrs);
        View.inflate(getContext(), R.layout.layout_service_platform_header, this);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.achieveRll})
    public void onClick(View view) {
        if (view.getId() == R.id.achieveRll) {
            TradeOpenProvider.getInstance().openAchievementActivity(getContext());
        }
    }

    public void showServicePlatformView(JSONObject jsonObject) {
        if (jsonObject != null) {
            if (jsonObject.containsKey("todayTradeAmount")) {
                todayTradeAmountTv.setText(VerifyUtil.decimalFormat(jsonObject.getString("todayTradeAmount")));
            }
            if (jsonObject.containsKey("todayTradeCount")) {
                todayTradeCountTv.setText(String.valueOf(jsonObject.getInteger("todayTradeCount")));
            }
            if (jsonObject.containsKey("totalMerchantNumber")) {
                totalMerchantNumberTv.setText(String.valueOf(jsonObject.getInteger("totalMerchantNumber")));
            }
            if (jsonObject.containsKey("todayProfit")) {
                todayProfitTv.setText(VerifyUtil.decimalFormat(jsonObject.getString("todayProfit")));
            }
            if (jsonObject.containsKey("todayTradeUser")) {
                todayTradeUserTv.setText(String.valueOf(jsonObject.getInteger("todayTradeUser")));
            }
            if (jsonObject.containsKey("merchantNumber")) {
                merchantNumberTv.setText(String.valueOf(jsonObject.getInteger("merchantNumber")));
            }
        }
    }
}
